﻿using IBLL;
using IDAL;
using Model;
using NPOI.OpenXmlFormats;

namespace BLL
{
    public class rkbll:IRKBLL
    {
        public rkbll(IRKDAL<yhmodel> dal)
        {
            Dal = dal;
        }

        public IRKDAL<yhmodel> Dal { get; }

        public Task<int> Add(yhmodel y)
        {
            return Dal.AddAsync(y);
        }

        public Task<int> Delete(int id)
        {
            var res = Dal.GetAll().FirstOrDefault(p=>p.Yid == id);
            return Dal.DeleteAsync(res);
        }

        public dynamic GetAll(int pageindex, int pagesize)
        {
           var H = Dal.GetAll().ToList();

            var K = from a in H
                    select new
                    {
                        a.Yid,
                        a.Yname,
                        a.Ydj,
                        a.Yqd,
                        a.Ysl,
                    };
            var count = K.Count();
            var list = K.OrderBy(p => p.Yid).Skip((pageindex-1)*pagesize).Take(pagesize).ToList();
            return new
            {
                count = count,
                list = list
            };
        }

        public Task<int> Update(yhmodel y)
        {
           return Dal.UpdateAsync(y);
        }
    }
}
